package com.lrkj.back.controller;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lrkj.back.entity.KcCangku;
import com.lrkj.back.service.KcChanpinService;
import com.lrkj.back.entity.KcChanpin;
import com.lrkj.back.service.KcCangkuService;
import com.lrkj.back.service.TbSeqService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.com.cbons.mamisay.parent.exception.BusinessException;

@Controller
@RequestMapping("/cangku")
public class ZsKCController extends BaseController {

    @Autowired
    private KcCangkuService kcCangkuService;

    @Autowired
    private KcChanpinService kcChanpinService;

    @Autowired
    private TbSeqService tbSeqService;

    @RequestMapping("/cangkuList.do")
    public ModelAndView cangkuList(HttpServletRequest request, HttpServletResponse response) throws BusinessException {
        // List list = new ArrayList<>();
        // list.contains(o);
        Map<String, Object> map = new HashMap<>();
        List<KcCangku> kcCangkuList = kcCangkuService.findCangku(map);
        request.setAttribute("kcCangkuList", kcCangkuList);
        return new ModelAndView("/kucun/cangku/kucun_cangku_mingxi");
    }

    @RequestMapping("/cangkuAdd.do")
    @ResponseBody
    public Map<String, Object> cangkuAdd(KcCangku cangku,HttpServletRequest request, HttpServletResponse response) throws BusinessException {
        Map<String,Object> rtnmap = new HashMap<>();
        kcCangkuService.insert(cangku);
        return rtnmap;
    }

    @RequestMapping("/chanpinList.do")
    public ModelAndView chanpinList(HttpServletRequest request, HttpServletResponse response) throws BusinessException {
        Map<String, Object> map = new HashMap<>();
        List<KcChanpin> kcChanpinList = kcChanpinService.findChanpin(map);
        request.setAttribute("kcChanpinList", kcChanpinList);
        return new ModelAndView("/kucun/chanpin/chanpinguanli");
    }

    @RequestMapping("/chanpinAdd.do")
    @ResponseBody
    public Map chanpinAdd(KcChanpin kccp,HttpServletRequest request, HttpServletResponse response) throws BusinessException {
        kccp.setKcChanpinId(String.valueOf(tbSeqService.seqVal("chanpin")));
        request.getParameter("kcThingPrice");
        BigDecimal bigprice = null;
        kccp.setKcThingPrice(bigprice);
        kcChanpinService.insert(kccp);
        Map<Object, Object> rtnMap = new HashMap<>();
        rtnMap.put("status", "true");
        rtnMap.put("msg", "保存成功");
        return rtnMap;

    }

}
